package com.quanyan.stadium.biz.redis.impl;

import com.quanyan.club.service.ClubOpenService;
import com.quanyan.place.client.PlaceClient;
import com.quanyan.redisCluster.utils.RedisConstants;
import com.quanyan.redisCluster.utils.RedisKey;
import com.quanyan.stadium.biz.redis.DefaultConfigCacheDao;
import com.quanyan.stadium.component.cache.MyRedisTemplate;
import com.quanyan.stadium.component.cache.StadiumRedisConstants;
import com.quanyan.stadium.entity.TbGameCommonParameter;
import com.quanyan.user.serviceFacade.UserServiceFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaoxiao
 * @date 16/4/11-14:42
 *
 * 缓存基础类
 */

@Service("defaultConfigCacheDaoImpl")
public class DefaultConfigCacheDaoImpl implements DefaultConfigCacheDao {

    private final static Logger logger = LoggerFactory.getLogger(DefaultConfigCacheDaoImpl.class);

    @Autowired
    private MyRedisTemplate myRedisTemplate;

    @Autowired
    private ClubOpenService clubOpenService;

    @Autowired
    private UserServiceFacade userServiceFacade;

    @Autowired
    private PlaceClient placeClient;

    private final static int EXPIRE_TIME = 60*10;


    @Override
    public void initTbGameCommonParameterMsgToCache(String groupKey, List<TbGameCommonParameter> list) {
        String key = StadiumRedisConstants.getUserCategoryAndCityScoreRankNum(groupKey);
        RedisKey redisKey = new RedisKey(RedisConstants.STADIUM_FAMILY_KEY, key);
        myRedisTemplate.setWithExpireTime(redisKey, list, EXPIRE_TIME);
    }

    @Override
    public List<TbGameCommonParameter> getTbGameCommonParameterListMsgFromCache(String groupKey) {
        String key = StadiumRedisConstants.getUserCategoryAndCityScoreRankNum(groupKey);
        RedisKey redisKey = new RedisKey(RedisConstants.STADIUM_FAMILY_KEY, key);
        return (List<TbGameCommonParameter>) myRedisTemplate.get(redisKey);
    }

    @Override
    public void delTbGameCommonParameterListMsgFromCache(String groupKey) {
        String key = StadiumRedisConstants.getUserCategoryAndCityScoreRankNum(groupKey);
        RedisKey redisKey = new RedisKey(RedisConstants.STADIUM_FAMILY_KEY, key);
        myRedisTemplate.delteKey(redisKey);
    }
}
